package demo518set;

import demo516.Emp;
import demo518.TestList;


import java.util.Scanner;

public class Demo {
    public static void main(String[] args) {
        TestSet testSet = new TestSet();
        Scanner scanner = new Scanner(System.in);

        boolean flag = true;
        while (flag) {
            System.out.println("欢迎来到员工系统");
            System.out.println("0.退出系统");
            System.out.println("1.添加员工");
            System.out.println("2.查询所有员工");
            System.out.println("3.根据姓名查询员工");
            System.out.println("4.根据编号删除员工");
            System.out.println("5.根据编号查询员工");
            System.out.println("6.根据编号改年龄");
            System.out.println("请选择功能");

            int n = scanner.nextInt();
            scanner.nextLine(); // 消耗换行符

            switch (n) {
                case 0:
                    System.out.println("退出系统");
                    flag = false;
                    break;

                case 1:
                    System.out.println("欢迎来到添加界面");
                    System.out.println("请输入员工的编号");
                    String addNumber = scanner.nextLine();
                    System.out.println("请输入员工姓名");
                    String addName = scanner.nextLine();
                    System.out.println("请输入员工的年龄");
                    int addAge = scanner.nextInt();
                    scanner.nextLine(); // 消耗换行符

                    Emp emp = new Emp();
                    emp.setNumber(addNumber);
                    emp.setName(addName);
                    emp.setAge(addAge);

                    testSet.addEmp(emp);
                    System.out.println("员工添加成功：" + emp);
                    break;

                case 2:
                    System.out.println("查询所有员工");
                    testSet.findAllEmp();
                    break;

                case 3:
                    System.out.println("根据姓名查询员工");
                    System.out.println("请输入要查询的员工姓名");
                    String empName = scanner.nextLine();

                    Emp foundEmp = testSet.findEmpName(empName);
                    System.out.println(foundEmp != null ? foundEmp : "未找到该员工");
                    break;

                case 4:
                    System.out.println("删除员工信息");
                    System.out.println("请输入要删除的员工编号");
                    String empNumber = scanner.nextLine();

                    testSet.deleteEmp(empNumber);
                    System.out.println("删除操作完成");
                    break;

                case 5:
                    System.out.println("根据编号查询员工");
                    System.out.println("请输入要查询的员工编号");
                    empNumber = scanner.nextLine();

                    emp = testSet.findEmpNumber(empNumber);
                    System.out.println(emp != null ? emp : "未找到该员工");
                    break;

                case 6:
                    System.out.println("根据编号改年龄");
                    System.out.println("请输入需修改的员工编号");
                    String updateNumber = scanner.nextLine();
                    System.out.println("请输入新的年龄");
                    int updateAge = scanner.nextInt();
                    scanner.nextLine(); // 消耗换行符

                    Emp existingEmp = testSet.findEmpNumber(updateNumber);
                    if (existingEmp != null) {
                        Emp updatedEmp = new Emp();
                        updatedEmp.setNumber(updateNumber);
                        updatedEmp.setName(existingEmp.getName());
                        updatedEmp.setAge(updateAge);

                        boolean success = testSet.updateEmp(updatedEmp);
                        if (success) {
                            System.out.println("员工年龄已更新为：" + updateAge);
                        } else {
                            System.out.println("更新失败，员工不存在");
                        }
                    } else {
                        System.out.println("未找到该员工");
                    }
                    break;

                default:
                    System.out.println("无效选择，请重新输入");
            }
        }
    }
}